<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveScaffold::Helpers::Associations</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveScaffold::Helpers::Associations</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/plugins/active_scaffold/lib/helpers/association_helpers_rb.html">
                vendor/plugins/active_scaffold/lib/helpers/association_helpers.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000176">association_options_count</a>&nbsp;&nbsp;
      <a href="#M000175">association_options_find</a>&nbsp;&nbsp;
      <a href="#M000177">options_for_association</a>&nbsp;&nbsp;
      <a href="#M000179">options_for_association_conditions</a>&nbsp;&nbsp;
      <a href="#M000178">options_for_association_count</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000176" class="method-detail">
        <a name="M000176"></a>

        <div class="method-heading">
          <a href="#M000176" class="method-signature">
          <span class="method-name">association_options_count</span><span class="method-args">(association, conditions = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000176-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000176-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/helpers/association_helpers.rb, line 9</span>
 9:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">association_options_count</span>(<span class="ruby-identifier">association</span>, <span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>)
10:         <span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">count</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:merge_conditions</span>, <span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:conditions</span>]))
11:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000175" class="method-detail">
        <a name="M000175"></a>

        <div class="method-heading">
          <a href="#M000175" class="method-signature">
          <span class="method-name">association_options_find</span><span class="method-args">(association, conditions = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Provides a way to honor the :conditions on an association while searching
the association&#8216;s klass
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000175-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000175-source">
<pre>
   <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/helpers/association_helpers.rb, line 5</span>
5:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">association_options_find</span>(<span class="ruby-identifier">association</span>, <span class="ruby-identifier">conditions</span> = <span class="ruby-keyword kw">nil</span>)
6:         <span class="ruby-identifier">association</span>.<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:merge_conditions</span>, <span class="ruby-identifier">conditions</span>, <span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:conditions</span>]))
7:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000177" class="method-detail">
        <a name="M000177"></a>

        <div class="method-heading">
          <a href="#M000177" class="method-signature">
          <span class="method-name">options_for_association</span><span class="method-args">(association)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
returns options for the given association as a collection of [id, label]
pairs intended for the <tt>options_for_select</tt> helper.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000177-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000177-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/helpers/association_helpers.rb, line 14</span>
14:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_for_association</span>(<span class="ruby-identifier">association</span>)
15:         <span class="ruby-identifier">available_records</span> = <span class="ruby-identifier">association_options_find</span>(<span class="ruby-identifier">association</span>, <span class="ruby-identifier">options_for_association_conditions</span>(<span class="ruby-identifier">association</span>))
16:         <span class="ruby-identifier">available_records</span> <span class="ruby-operator">||=</span> []
17:         <span class="ruby-identifier">available_records</span>.<span class="ruby-identifier">sort</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>,<span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_label</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">to_label</span>}.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">model</span><span class="ruby-operator">|</span> [ <span class="ruby-identifier">model</span>.<span class="ruby-identifier">to_label</span>, <span class="ruby-identifier">model</span>.<span class="ruby-identifier">id</span> ] }
18:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000179" class="method-detail">
        <a name="M000179"></a>

        <div class="method-heading">
          <a href="#M000179" class="method-signature">
          <span class="method-name">options_for_association_conditions</span><span class="method-args">(association)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A useful override for customizing the records present in an association
dropdown. Should work in both the subform and form_ui=&gt;:select modes.
Check association.name to specialize the conditions per-column.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000179-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000179-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/helpers/association_helpers.rb, line 27</span>
27:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_for_association_conditions</span>(<span class="ruby-identifier">association</span>)
28:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">association</span>.<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:through</span>]
29:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">association</span>.<span class="ruby-identifier">macro</span>
30:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:has_one</span>, <span class="ruby-identifier">:has_many</span>
31:             <span class="ruby-comment cmt"># Find only orphaned objects</span>
32:             <span class="ruby-node">&quot;#{association.primary_key_name} IS NULL&quot;</span>
33:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:belongs_to</span>, <span class="ruby-identifier">:has_and_belongs_to_many</span>
34:             <span class="ruby-comment cmt"># Find all</span>
35:             <span class="ruby-keyword kw">nil</span>
36:         <span class="ruby-keyword kw">end</span>
37:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000178" class="method-detail">
        <a name="M000178"></a>

        <div class="method-heading">
          <a href="#M000178" class="method-signature">
          <span class="method-name">options_for_association_count</span><span class="method-args">(association)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000178-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000178-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/helpers/association_helpers.rb, line 20</span>
20:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options_for_association_count</span>(<span class="ruby-identifier">association</span>)
21:         <span class="ruby-identifier">association_options_count</span>(<span class="ruby-identifier">association</span>, <span class="ruby-identifier">options_for_association_conditions</span>(<span class="ruby-identifier">association</span>))
22:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>